import Vue from 'vue'

import VueRouter from 'vue-router'

Vue.use(VueRouter)


const routes = [
  {
   path:'/',
   redirect: '/login',
  },
  {
    path:'/login',
    component:()=>import( '../views/login/Login.vue')
  },
  {
    path:'/layout',
    redirect: '/home',
    component:()=>import( '../views/layout/Layout.vue'),
    children:[
      {
        path:'/home',
        name:'首页',
        component:()=>import('../views/home/Home.vue')
      },
      {
        path:'/pms',
        name:'商品',
        component:()=>import('../views/other/pms.vue'),
        children:[
          {
            path:'/pms/product',
            name:'商品列表',
            component:()=>import('../views/products/ProductList.vue')
          },
          {
            path:'/pms/addProduct',
            name:'添加商品',
            component:()=>import('../views/products/AddProduct.vue')
          },
          {
            path:`/pms/updateProductCate`,
            name:'修改商品分类',
            component:()=>import('../views/products/UpdatedProduct.vue')
          },
          {
            path:'/pms/productCate',
            name:'商品分类',
            component:()=>import('../views/products/ClassifyProduct.vue')
          },
          {
            path:'/pms/productAttr',
            name:'商品分类',
            component:()=>import('../views/products/ProductType.vue')
          },
          {
            path:'/pms/brand',
            name:'品牌管理',
            component:()=>import('../views/products/RegulateBrand.vue')
          },
          {
            path:'/pms/updateBrand',
            name:'编辑品牌',
            component:()=>import('../views/products/EditProduct')
          },
        ]
      },
      {
        path:'/oms',
        name:'订单',
        component: ()=>import('../views/other/oms.vue'),
        children:[
          {
            path:'/oms/order',
            name:'订单列表',
            component:()=>import('../views/order/OrderList.vue'),
          },
          {
            path:'/oms/orderDetail',
            name:'订单详情',
            component: ()=>import('../views/order/OrderDetails.vue')
          },
          {
            path:'/oms/orderSetting',
            name:'订单设置',
            component:()=>import('../views/order/OrderSetting')
          },
          {
            path:'/oms/deliverOrderList',
            name:'发货列表',
            component:()=>import('../views/order/DeliverOrderList.vue')
          },
          {
            path:'/oms/returnApply',
            name:'退货申请处理',
            component:()=>import('../views/order/ReturnApply')
          },{
            path:'/oms/returnApplyDetail',
            name:'退货原因详情',
            component:()=>import('../views/order/ReturnsDetails.vue')
          },{
            path:'/oms/returnReason',
            name:'退货原因设置',
            component:()=>import('../views/order/ReturnReason.vue')
          }
        ]
      },
      {
        path:'/sms',
        name:'营销',
        component: ()=>import('../views/other/sms.vue'),
        children:[
          {
            path:'/sms/homeAdvertise',
            name:'订单列表',
            component:()=>import('../views/market/HomeAdvertise.vue'),
          },
        ]
      }
    ]
  },
]

const router = new VueRouter({
  routes,
})

// router.beforeEach((to,form,next)=>{
//   let paths = to.path
//   let names = to.path.slice(1)
//   let ro = {
//     path: paths,
//     name:names,
//     component:()=> import('../views/'+names+'/'+names.charAt(0).toUpperCase()+names.slice(1)),  // 路由懒加载,
//   }
//   let flag = router.getRoutes().some((item)=>item.name == names) // 获取所有当前路由表信息
//   if(flag){ // 如果有就直接放行
//     next()
//   }else{
//     router.addRoute(ro) // 没有则增加路由信息
//     next({...ro,replace:true})
//   }
// })

export default router
  
 